package main;

import java.util.*;
class PersonSortable2 {
	
	private String name;
	private int age;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
		
		
	public PersonSortable2(String name,int age) {
		this.name = name;
		this.age=age;
		
	}
	@Override
	public String toString() {
		return name + "-" + age;
	}
}
	
class NameComparator implements Comparator<PersonSortable2>{
	       
	            @Override
	            public int compare(PersonSortable2 o1, PersonSortable2 o2) {
	                return o1.getName().compareTo(o2.getName());
	            }
	            
	};
	 class AgeComparator implements Comparator<PersonSortable2>{
		 
	                    
	                        @Override
	                        public int compare(PersonSortable2 o1, PersonSortable2 o2) {
	                            if (o1.getAge() > o2.getAge()) {
	                                return 1;
	                            } else if (o1.getAge() < o2.getAge()) {
	                                return -1;
	                            } else {
	                                return 0;
	                            }
	                        }
	                };
	

	
	




public class main3 {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=Integer.parseInt(sc.nextLine());
		String ss[]=new String[n];
		PersonSortable2[] st = new PersonSortable2[n];
		
		for(int i=0;i<n;i++){
			ss[i]=sc.nextLine();
			String[] s=ss[i].split(" ");
			int a=Integer.parseInt(s[1]);
			st[i]=new PersonSortable2(s[0],a);
			
		}
		Arrays.sort(st,new NameComparator());
		System.out.println("NameComparator:sort");
		for(PersonSortable2 e:st){
			System.out.println(e);
		}
		Arrays.sort(st,new AgeComparator());
		System.out.println("AgeComparator:sort");
		for(PersonSortable2 e:st){
			System.out.println(e);
		}
		System.out.println(Arrays.toString(NameComparator.class.getInterfaces()));
		System.out.println(Arrays.toString(AgeComparator.class.getInterfaces()));
	}

}

